﻿using System;
using System.Collections.Generic;
using MAF.UserSecurity.Repository;
using MAF.Common;

namespace MAF.UserSecurity
{
    public static class Manager
    {
        private static UserRepo _UserRepo;
        private static UserContextRepo _UserContextRepo;

        static Manager()
        {
            _UserRepo = UserRepo.Instance;
            _UserContextRepo = new UserContextRepo();
        }

        #region 用户管理

        /// <summary>
        /// 存储新用户
        /// </summary>
        /// <param name="info"></param>
        public static void  AddUser(User info)
        {
            if (UserContext.Current.IsInRole(""))
            _UserRepo.Add(info);
        }

        /// <summary>
        /// 更新用户
        /// </summary>
        /// <param name="info"></param>
        public static void  UpdateUser(User info)
        {
            _UserRepo.Update(info);
        }

        /// <summary>
        /// 移除用户
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public static int  RemoveUser(Guid id)
        {
            return _UserRepo.Remove(id);
        }

        /// <summary>
        /// 查询用户明细
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static User GetUser(Guid id)
        {
            return _UserRepo.GetById(id);
        }

        /// <summary>
        /// 查询用户清单
        /// </summary>
        /// <param name="vo"></param>
        /// <returns></returns>
        public static List<User> GetUserList(Query<User> q)
        {
            return _UserRepo.GetByQuery(q);
        }

        /// <summary>
        /// 查询用户清单的数量
        /// </summary>
        /// <param name="vo"></param>
        /// <returns></returns>
        public static int CountUserList(Query<User> q)
        {
 	        return _UserRepo.CountByQuery(q);
        }

        #endregion
    }
}
